package servlet;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.ContentsDAO;
import dao.WebUserDAO;
import entity.Contents;
import entity.WebUser;

@WebServlet("/servlet/CheckServlet")
public class CheckServlet extends HttpServlet {
	private ContentsDAO dao = new ContentsDAO();
	private String action ;
    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        //TODO Method stub generated by Lomboz
        this.doPost(request, response);
    }
    private String list(HttpServletRequest request) {
        try {
            request.setAttribute("objlist", dao.loadAllContents());
            return "/home_page.jsp";
        } catch (Exception ex) {
            request.setAttribute("errormsg", ex.getMessage());
            return "/error.jsp";
        }
    }
    
    private void contents_edit(HttpServletRequest request){
    	 try {

    		 this.dao.editContents(request.getParameter("cno"));
		 } catch (Exception ex) {
			 
	         request.setAttribute("errormsg", ex.getMessage());
	         
	     }
    }
    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        this.action = request.getParameter("action");
        if (action.equals("edit"))
	      {
        	contents_edit(request);
		
	      }
        else if(action.equals("delt"))
        {
        	contents_delt(request);
        }
      	request.getRequestDispatcher("/ht_check.jsp").forward(request, response);   	
    }
	private void contents_delt(HttpServletRequest request) {
   	 try {
   		 this.dao.delContents(request.getParameter("cno"));

	 } catch (Exception ex) {
		 
         request.setAttribute("errormsg", ex.getMessage());
         
     }
		
	}
}
